package com.example.zhxy.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.zhxy.pojo.Student;
import com.example.zhxy.service.StudentService;
import com.example.zhxy.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
/**
 * CJ
 */
@Api(tags = "学生管理控制器")
@RestController
@RequestMapping("/sms/studentController")
public class StudentController {
    @Autowired
    private StudentService studentService;
    @ApiOperation("分页")
    @GetMapping("/getStudentByOpr/{pageNo}/{pageSize}")
    public Result page(@PathVariable Integer pageNo, @PathVariable Integer pageSize, Student student){
        Page<Student> page=new Page<>();
        IPage page1=studentService.IPage(page,student);
        return Result.ok(page1);
    }
    @ApiOperation("新增或修改")
    @PostMapping("/addOrUpdateStudent")
    public Result addOrUpdateStudent(@RequestBody Student student){
        studentService.addOrUpdateStudent(student);
        return Result.ok();

    }
    @ApiOperation("批量删除")
    @DeleteMapping("/delStudentById")
    public Result delStudentById(@RequestBody List<Integer> list){
        boolean b=studentService.delStudentById(list);
        if(b){
            return Result.ok();
        }else {
            return Result.fail().message("批量删除失败");
        }

    }
}
